'''
Created on Jun 21, 2012
Class to decode encrypted passwords from configuration 

@author: vukasin.n@gmail.com
# According to tutorial: http://www.codekoala.com/blog/2009/aes-encryption-python-using-pycrypto/
'''

from Crypto.Cipher import AES
import base64

########################################################################
class Crypto():
    """"""
        
    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""

    def decode(self, password):
        
        s1 = '$!F*Us'
        e2 = 'ju^3)('
        c3 = '^%^##!'
        r4 = '@#HHAW'
        tr = s1 + e2
        rt = c3 + r4
        ret = tr + rt
        
        PADDING = '`'
        
        secret = ret
        
        cipher = AES.new(secret,AES.MODE_CFB)
        
        decoded = cipher.decrypt(base64.b64decode(password)).rstrip(PADDING)
    
        return decoded
    